package de.tudarmstadt.ukp.muip.fibqdojo.visitor;

import java.util.List;

import com.google.common.base.Optional;

import de.tudarmstadt.ukp.muip.fibqdojo.Sentence;
import de.tudarmstadt.ukp.muip.fibqdojo.SentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.Token;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IStructureVisitor;
import de.tudarmstadt.ukp.muip.fibqdojo.japanese.JapaneseToken;

/**
 * Determines the kind of Token used in a sentence. If a sentence is visited
 * with this visitor, the first token is visited and assumed that all other
 * tokens are of the same kind as the first one.
 * 
 * Kinds: (1) Token (2) JapaneseToken .... append if new token kinds are added
 * 
 * @author Tobias Horsmann
 */
public class DetermineTokenKindVisitor implements IStructureVisitor {

    private Optional<Integer> kind = Optional.absent();

    public Optional<Integer> getKind() {
        return kind;
    }

    @Override
    public void visit(JapaneseToken token) {
        kind = Optional.of(2);
    }

    @Override
    public void visit(Token token) {
        kind = Optional.of(1);
    }

    @Override
    public void visit(SentenceToken token) {
        token.getToken().accept(this);
    }

    /**
     * The first token decides the kind of token of the full sentences!
     */
    @Override
    public void visit(Sentence sentence) {
        List<IFIBQSentenceToken> sentenceTokens = sentence.getSentenceTokens();
        if (sentenceTokens.size() > 1) {
            sentenceTokens.get(0).accept(this);
        }
    }

}
